<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:p="http://primefaces.org/ui"
                xmlns:ez="http://java.sun.com/jsf/composite/ezcomp"
                xmlns:pe="http://primefaces.org/ui/extensions"
                xmlns:cashier="http://java.sun.com/jsf/composite/cashier">


    <ui:define name="content">

        <h:panelGroup rendered="true" >
            <h:form>
                <h:outputStylesheet library="css" name="printing.css"></h:outputStylesheet>
                <p:panel id="reportPrint" styleClass="noBorder summeryBorder" header="Casheir Session Report Detail">

                    <f:facet name="header" >
                        <h:outputLabel value="#{labels.company_name}"/> <br/>

                        <p:commandButton  id="btnRefresh" ajax="false" value="Refresh" 
                                          styleClass="noPrintButton" 
                                         actionListener="#{commonReport.createTableByBillType()}" style="float: right;" />  
                        <p:defaultCommand target="btnRefresh"/>

                        <p:commandButton ajax="false" value="Print" styleClass="noPrintButton" style="float: right;" >
                            <p:printer target="reportPrint"/>
                        </p:commandButton>  
                        <p:commandButton ajax="false" actionListener="#{commonReport.createTableByBillType()}" value="Excel"  styleClass="noPrintButton" style="float: right;" >
                            <pe:exporter type="xlsx" 
                                         target="#{commonReport.institutionBilledBillsOwn.bills.size()>0 and commonReport.billType eq 'OpdBill' ?'billed,':''}
                                         #{commonReport.institutionCancelledBillsOwn.bills.size() ne 0 and commonReport.billType eq 'OpdBill' ?'cancelled,':''}
                                         #{commonReport.institutionRefundedBillsOwn.bills.size() ne 0 and commonReport.billType eq 'OpdBill' ?'refunded,':''}
                                         #{commonReport.institutionBilledBillsOwnPh.bills.size() ne 0 ?'billedPh,':''}
                                         #{commonReport.institutionCancelledBillsOwnPh.bills.size() ne 0 ?'cancelledPh,':''}
                                         #{commonReport.institutionRefundedBillsOwnPh.bills.size() ne 0 ?'refundPh,':''}
                                         #{commonReport.institutionPaymentBillsOwn.bills.size() ne 0  and commonReport.billType eq 'PaymentBill'?'payment,':''}
                                         #{commonReport.institutionPaymentCancelBillsOwn.bills.size() ne 0 and commonReport.billType eq 'PaymentBill' ?'paymentCancel,':''}
                                         #{commonReport.institutionPettyPaymentBillsOwn.bills.size() ne 0 and commonReport.billType eq 'PettyCash' ?'petty,':''}
                                         #{commonReport.institutionPettyCancellBillsOwn.bills.size() ne 0 and commonReport.billType eq 'PettyCash' ?'pettyCancel,':''}
                                         #{commonReport.institutionCashRecieveBillsOwn.bills.size() ne 0 and commonReport.billType eq 'CashRecieveBill' ?'companyPay,':''}
                                         #{commonReport.institutionCashRecieveCancellBillsOwn.bills.size() ne 0 and commonReport.billType eq 'CashRecieveBill' ?'companyCancel,':''}
                                         #{commonReport.institutionAgentBillsOwn.bills.size() ne 0 and  commonReport.billType eq 'AgentPaymentReceiveBill'?'agent,':''}
                                         #{commonReport.institutionAgentCancellBillsOwn.bills.size() ne 0 and  commonReport.billType eq 'AgentPaymentReceiveBill' ?'agentCancel,':''}
                                         #{commonReport.institutionInwardPaymentBillsOwn.bills.size() ne 0 and  commonReport.billType eq 'InwardPaymentBill' ?'inward,':''}
                                         #{commonReport.institutionInwardPaymentCancelBillsOwn.bills.size() ne 0 and  commonReport.billType eq 'InwardPaymentBill' ?'inwardCancel,':''}
                                         sum"  fileName="Day_END_By_Bill_Type" />
                        </p:commandButton> 
                        <h:panelGrid columns="7" styleClass="printBlock" style="min-width: 100%;">
                            <h:panelGroup>
                                <h:outputLabel value="#{commonReport.webUser.webUserPerson.name} "/>
                                <h:outputLabel value="Cashier Day End Detailed Report "/>
                            </h:panelGroup>
                            <p:spacer width="20" height="0"/>
                            <h:outputLabel value="From" />
                            <h:outputLabel  value="#{commonReport.fromDate}" >
                                <f:convertDateTime pattern="dd MMMM yyyy HH:mm:ss"/>
                            </h:outputLabel>
                            <p:spacer width="10" height="0"/>
                            <h:outputLabel value="To"/>
                            <h:outputLabel  value="#{commonReport.toDate}" style="float: right" >
                                <f:convertDateTime pattern="dd MMMM yyyy HH:mm:ss"/>
                            </h:outputLabel>
                        </h:panelGrid>
                    </f:facet>


                    <h:panelGrid columns="8" styleClass="noPrintButton" >
                        <h:outputLabel value="From Date"/>
                        <p:calendar id="frmDate" value="#{commonReport.fromDate}" navigator="true"  pattern="dd MM yy HH:mm:ss a" >
                        </p:calendar>

                        <h:outputLabel value="To Date"/>
                        <p:calendar id="toDate" value="#{commonReport.toDate}" navigator="true" pattern="dd MM yy HH:mm:ss a" >
                        </p:calendar>

                        <h:outputLabel styleClass="noPrintButton" value="User Name"/>
                        <p:autoComplete converter="webUs" completeMethod="#{webUserController.completeUser}" styleClass="noPrintButton"
                                        forceSelection="true"
                                        var="w" itemLabel="#{w.webUserPerson.name}" itemValue="#{w}"
                                        value="#{commonReport.webUser}" ></p:autoComplete>

                        <h:outputLabel value="Select Bill Type"/>
                        <h:selectOneMenu value="#{commonReport.billType}">
                            <f:selectItem itemLabel="Select Bill Type"/>
                            <f:selectItems value="#{enumController.cashFlowBillTypes}" var="i" itemLabel="#{i.label}" itemValue="#{i}" />
                        </h:selectOneMenu>
                    </h:panelGrid>


                    <h:panelGroup  >      
                        <p:dataTable id="billedPh"  value="#{commonReport.billedBills.bills}" var="b" sortBy="#{b.billType}"  >

                            <f:facet name="header">  
                                <h:outputLabel value="Opd Bills "/>
                            </f:facet>

                            <p:column headerText="Time"  >
                                <f:facet name="header">  
                                    <h:outputLabel value="Time"/>
                                </f:facet> 
                                <h:outputLabel value="#{b.createdAt}" >
                                    <f:convertDateTime pattern="h:mm a"/>
                                </h:outputLabel>
                            </p:column>

                            <p:column headerText="Cashier"  >
                                <f:facet name="header">  
                                    <h:outputLabel value="Cashier"/>
                                </f:facet> 
                                <h:outputLabel value="#{b.creater.webUserPerson.name}"/>
                            </p:column>

                            <p:column headerText="Id" >
                                <f:facet name="header">  
                                    <h:outputLabel value="Id"/>
                                </f:facet> 
                                <h:outputLabel value="#{b.insId}"/>
                            </p:column>

                            <p:column headerText="To Department"  >
                                <f:facet name="header">  
                                    <h:outputLabel value="To Department"/>
                                </f:facet> 
                                <h:outputLabel value="#{b.toDepartment.name}"/>

                            </p:column>

                            <p:column headerText="Patient Name" >
                                <f:facet name="header">  
                                    <h:outputLabel value="Patient Name"/>
                                </f:facet> 
                                <h:outputLabel value=" #{b.patient.person.nameWithTitle}"/>               
                            </p:column>

                            <p:column headerText="Dis." style=" text-align: right">
                                <f:facet name="header">  
                                    <h:outputLabel value="Dis."/>
                                </f:facet> 
                                <h:outputLabel value="#{b.discount}">
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputLabel>
                            </p:column>

                            <p:column headerText="Cash" style=" text-align: right"  >
                                <f:facet name="header">  
                                    <h:outputLabel value="Cash"/>
                                </f:facet> 
                                <h:outputLabel rendered="#{b.paymentMethod=='Cash'}" value="#{b.netTotal}" >
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputLabel>
                                <h:outputLabel rendered="#{b.paymentMethod!='Cash'}" value="0.00" />
                            </p:column>

                            <p:column headerText="Credit" style=" text-align: right" >
                                <f:facet name="header">  
                                    <h:outputLabel value="Credit"/>
                                </f:facet> 
                                <h:outputLabel rendered="#{b.paymentMethod=='Credit'}" value="#{b.netTotal}"  >
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputLabel>
                                <h:outputLabel rendered="#{b.paymentMethod!='Credit'}" value="0.00"/>
                            </p:column>

                            <p:column headerText="C Card" style=" text-align: right" >
                                <f:facet name="header">  
                                    <h:outputLabel value="C Card"/>
                                </f:facet> 
                                <h:outputLabel rendered="#{b.paymentMethod=='Card'}" value="#{b.netTotal}" >
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputLabel>
                                <h:outputLabel rendered="#{b.paymentMethod!='Card'}" value="0.00"/>
                            </p:column>

                            <p:column headerText="Checque" style=" text-align: right" >
                                <f:facet name="header">  
                                    <h:outputLabel value="Checque"/>
                                </f:facet> 
                                <h:outputLabel rendered="#{b.paymentMethod=='Cheque'}" value="#{b.netTotal}" >
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputLabel>
                                <h:outputLabel rendered="#{b.paymentMethod!='Cheque'}" value="0.00"/>
                            </p:column>

                            <p:column headerText="Slip" style=" text-align: right" >
                                <f:facet name="header">  
                                    <h:outputLabel value="Slip"/>
                                </f:facet> 
                                <h:outputLabel rendered="#{b.paymentMethod=='Slip'}" value="#{b.netTotal}" >
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputLabel>
                                <h:outputLabel rendered="#{b.paymentMethod!='Slip'}" value="0.00"/>
                            </p:column>

                            <p:column headerText="Remark" >
                                <f:facet name="header">  
                                    <h:outputLabel value="Remark"/>
                                </f:facet> 
                                <h:outputLabel value="Cancelled. (#{b.cancelledBill.insId})" rendered="#{b.cancelled==true}" ></h:outputLabel>
                            </p:column>

                            <p:columnGroup type="footer">  
                                <p:row >  
                                    <p:column colspan="6" style="text-align:left" footerText="Totals:"/>

                                    <p:column footerText="#{commonReport.billedBills.cash}">
                                        <f:facet name="footer">
                                            <h:outputLabel value="#{commonReport.billedBills.cash}">
                                                <f:convertNumber pattern="#,##0.00"/>
                                            </h:outputLabel>
                                        </f:facet>
                                    </p:column>

                                    <p:column footerText="#{commonReport.billedBills.credit}">
                                        <f:facet name="footer">
                                            <h:outputLabel value="#{commonReport.billedBills.credit}">
                                                <f:convertNumber pattern="#,##0.00"/>
                                            </h:outputLabel>
                                        </f:facet>
                                    </p:column>  


                                    <p:column footerText="#{commonReport.billedBills.card}">
                                        <f:facet name="footer">
                                            <h:outputLabel value="#{commonReport.billedBills.card}">
                                                <f:convertNumber pattern="#,##0.00"/>
                                            </h:outputLabel>
                                        </f:facet>
                                    </p:column>  

                                    <p:column footerText="#{commonReport.billedBills.cheque}">
                                        <f:facet name="footer">
                                            <h:outputLabel value="#{commonReport.billedBills.cheque}">
                                                <f:convertNumber pattern="#,##0.00"/>
                                            </h:outputLabel>
                                        </f:facet>
                                    </p:column> 

                                    <p:column footerText="#{commonReport.billedBills.slip}">
                                        <f:facet name="footer">
                                            <h:outputLabel value="#{commonReport.billedBills.slip}">
                                                <f:convertNumber pattern="#,##0.00"/>
                                            </h:outputLabel>
                                        </f:facet>
                                    </p:column>

                                </p:row>  
                            </p:columnGroup>  

                        </p:dataTable>

                        <p:spacer height="30"/>


                        <p:dataTable id="sum" value="#{commonReport.dataTableDataByType2}"  var="i" >
                            <f:facet name="header">
                                Summary
                            </f:facet>
                            <p:column>
                                <h:outputLabel value="#{i.string}"/>
                            </p:column>
                            <p:column style="font-weight: bold;text-align:right;" >
                                <h:outputLabel value="#{i.value}">
                                    <f:convertNumber pattern="#,##0.00" />
                                </h:outputLabel>
                            </p:column>
                        </p:dataTable>


                </p:panel>
            </h:form>
        </h:panelGroup>
    </ui:define>

</ui:composition>
